const Base = require('../../base.js');

module.exports = class extends Base {
  async indexAction() {
    let userInfo = await this.session('user_info')
    if (!userInfo) return this.fail(-1, '用户未登录')
    let data = {
      _id: this.post('_id'),
    }
    if (this.post('nickname')) data.nickname = this.post('nickname')
    if (this.post('phone')) data.phone = this.post('phone')
    if (this.post('phone')) data.phone = this.post('phone')
    if (this.post('headpic')) data.headpic = this.post('headpic')
    if (this.post('password')) data.password = think.encodePwd(this.post('password'))

    await this.model('user/index').edit(data)
    this.json({
      status: 200, message: 'success'
    })
  }
};
